
#include <stdio.h>
#include <stdlib.h>
#include <testpackage.h>

// #define _SPJ_DEBUG_MODE

int main() {
	struct judge_fs *fs;
	uint32_t i, testcase_count, spj_key_count;
	const char *path_in[100], *path_out[100], *path, *spj_prefix, *spj_key[100];
	char buffer[1024];
	struct judge_file *file;
	size_t sz;

#ifndef _SPJ_DEBUG_MODE
	package_create(&fs, "D:\\test\\test.zip");
#else
	package_create(&fs, "D:\\test\\test_spj.zip");
#endif

	package_get_metadata(fs, NULL, NULL, &testcase_count, path_in, path_out, &spj_prefix, &spj_key_count, spj_key);

#ifndef _SPJ_DEBUG_MODE
	for (i = 0; i < testcase_count; i += 1) {
		printf("Testcase: %d\n", i); 

		printf("[Input] %s\n", path_in[i]);
		fs->vtable.open(fs, &file, path_in[i]);
		fs->vtable.read(fs, file, buffer, 1024, &sz);
		buffer[sz] = 0;
		printf("%s\n", buffer);
		fs->vtable.close(fs, file);

		printf("[Output] %s\n", path_out[i]);
		fs->vtable.open(fs, &file, path_out[i]);
		fs->vtable.read(fs, file, buffer, 1024, &sz);
		buffer[sz] = 0;
		printf("%s\n", buffer);
		fs->vtable.close(fs, file);
	}
#else
	for (i = 0; i < spj_key_count; i += 1) {
		printf("Testcase: %d\n", i); 
		printf("[SPJ Key] %s\n", spj_key[i]);
	}
	void *context = 0;
	jstatus_t st = fs->vtable.find(fs, &path, spj_prefix, &context);
	while (JSUCCESS(st) && path) {
		printf("[Path]: %s\n", path);
		st = fs->vtable.find(fs, &path, spj_prefix, &context);
	}
#endif
	package_destroy(fs);
	return 0;
}
